/*
 * HeartRateInterrupt.h
 *
 *  Created on: 14/04/2013
 *      Author: roger
 */

#ifndef HEARTRATEINTERRUPT_H_
#define HEARTRATEINTERRUPT_H_
#include "Arduino.h"
#include "Configuration.h"

#define PREVBUFSIZE 30
#define SLOPE 8
#define HIGH_CUTOFF 510
#define LOW_CUTOFF 480

// Assign human-readable names to some common 16-bit color values:
#define	BLACK   0x0000
#define	BLUE    0x001F
#define	RED     0xF800
#define	GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

class HeartRateInterrupt {
private:
	volatile int m_prev[PREVBUFSIZE];
	int m_lastSign;
	long m_lastPeakTime;
	long m_bpm;
	long m_runningTime;
	long m_counter;
	long m_lastRunningTotal;
	bool m_logRawData = false;
	int m_high;
	int m_low;
	int m_slope;
	int m_troughBottom;
	int m_troughTime;
	float m_my;
	bool m_effects;
	float m_lastInterval;

public:
	HeartRateInterrupt(long startTime);
	virtual ~HeartRateInterrupt();
	int getCurrentBPM();
	void calculate(int signal);
	void poincarePlot(float interval, float lastInterval);
	bool isLogRawData() const {
		return m_logRawData;
	}
	void setLogRawData(bool logRawData = false);

	void setEffects(bool effects) {
		m_effects = effects;
	}

	float getLastInterval() const {
		return m_lastInterval;
	}

	volatile int BPM; // used to hold the pulse rate
	volatile int averageBPM; // used to hold the pulse rate
	volatile int averageBPMCount; // used to hold the pulse rate
};

extern HeartRateInterrupt heartRateInterrupt;

#endif /* HEARTRATEINTERRUPT_H_ */
